<template>
  <div>
    <!--    面包屑-->
    <el-breadcrumb separator-class="el-icon-arrow-right"
                   style="padding-left: 10px;padding-bottom: 10px;font-size: 12px">
      <el-breadcrumb-item :to="{ path: '/main' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>系统管理</el-breadcrumb-item>
      <el-breadcrumb-item>用户管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!--    卡片-->`
    <el-card class="box-card">
      <el-form :inline="true" :model="userVo" class="demo-form-inline">
        <el-form-item label="部门" label-width="120px">
          <el-select clearable v-model="userVo.departmentId" placeholder="请选择">
            <el-option
              v-for="item in department"
              :key="item.id"
              :label="item.name"
              :value="item.id">
              <span style="float: left">{{ item.name }}</span>
              <span style="float: right; color: #8492a6; font-size: 13px">
                <span class="el-tag el-tag--success el-tag--mini el-tag--plain">{{ item.deptCount }}</span>
              </span>
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="用户名" label-width="120px">
          <el-input clearable v-model="userVo.username" placeholder="请输入用户名"></el-input>
        </el-form-item>
        <el-form-item label="邮箱" label-width="120px">
          <el-input clearable v-model="userVo.email" placeholder="请输入邮箱"></el-input>
        </el-form-item>
        <el-form-item label-width="120px">
          <el-radio v-model="userVo.sex" label="0">男</el-radio>
          <el-radio v-model="userVo.sex" label="1">女</el-radio>
          <el-radio v-model="userVo.sex" label="">全部</el-radio>
        </el-form-item>
        <el-form-item label="昵称" label-width="120px">
          <el-input clearable v-model="userVo.nickname" placeholder="请输入昵称"></el-input>
        </el-form-item>

        <el-form-item style="margin-left: 60px">
          <el-button icon="el-icon-refresh" @click="resetUerVo">重置</el-button>
          <el-button type="primary" icon="el-icon-search" @click="getUserList">查询</el-button>
          <el-button type="success" icon="el-icon-plus">添加</el-button>
          <el-button type="warning" icon="el-icon-download">导出</el-button>
        </el-form-item>
      </el-form>

      <!--      表格内容显示区域-->
      <el-table
        :data="userList"
        border
        style="width: 100%" height="600px">
        <el-table-column
          prop="id"
          label="#"
          width="50">
        </el-table-column>
        <el-table-column
          prop="username"
          label="用户名"
          width="110">
        </el-table-column>
        <el-table-column
          prop="sex"
          label="性别"
          width="110">
          <template slot-scope="scope">
            {{scope.row.sex ==0?'男':(scope.row.sex ==1?'女':'保密')}}
          </template>
        </el-table-column>
        <el-table-column
          sortable
          prop="name"
          label="所属部门"
          width="180">
        </el-table-column>
        <el-table-column
          sortable
          prop="birth"
          label="生日"
          width="180">
        </el-table-column>
        <el-table-column
          prop="email"
          label="邮箱"
          width="180">
        </el-table-column>
        <el-table-column
          prop="phoneNumber"
          label="电话"
          width="150">
        </el-table-column>
        <el-table-column
          prop="status"
          label="是否禁用"
          width="100">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.status==1"
              active-color="#13ce66"
              inactive-color="#ff4949">
            </el-switch>
          </template>
        </el-table-column>
        <el-table-column
          label="操作">
          <el-button type="primary" size="mini" icon="el-icon-edit"></el-button>
          <el-button type="danger" size="mini" icon="el-icon-delete"></el-button>
          <el-button type="warning" size="mini" icon="el-icon-s-tools"></el-button>
        </el-table-column>
      </el-table>

      <!--      分页-->
      <el-pagination
        style="padding-top: 15px"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="current"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
  import {findUserList} from "../../api/users"
  import {findDeptAndCount} from "../../api/dept"

  export default {
    name: 'Users',
    data() {
      return {
        userVo: {
          departmentId: '',
          username: '',
          email: '',
          sex: '1',
          nickname: '',
        },
        //用户列表集合
        userList:[],
        //部门集合
        deptList:[],
        current: 1,
        size:10,
        total:100,
        department:[],
      }
    },
    created(){
    //  创建组件的时候调用查询所有用户方法
      this.getUserList();
      this.getDeptAndCount();
    },
    methods: {
      onSubmit() {
        console.log('submit!');
      },
      //当每页条数改变时
      handleSizeChange(val) {
        this.size = val;
        this.getUserList();
      },
      //当前页码改变时
      handleCurrentChange(val) {
        this.current = val;
        this.getUserList();
      },

     async getUserList(){
       const { data } = await findUserList(this.current,this.size,this.userVo)
       console.log(data);
       this.userList = data.data.records;
       this.total=data.data.total;
      },

      async getDeptAndCount(){
        const{ data } = await findDeptAndCount()
        this.department=data.data.department;
      },
      resetUerVo(){
        this.userVo.departmentId='';
        this.userVo.email='';
        this.userVo.nickname='';
        this.userVo.username='';
        this.userVo.sex="1";
        this.getUserList();
      }
    },






  }
</script>

<style scoped>

</style>
